<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>qq联系人</title>
    <script src="../jquery/jquery.min.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .contacts{
            width: 240px;
            height: 400px;
            border: 1px solid #ccc;
            margin: 30px auto;
            text-align: center;
        }
        .group h2{
            background-color: #eee;
            border-bottom: 1px solid #ccc;
        }
        .hide{
            display: none;
        }
    </style>
</head>
<body>
    <div class="contacts">
        <div class="group">
            <h2>大学同学</h2>
            <div class="ps">
                <p>1</p>
                <p>2</p>
                <p>3</p>
            </div>
        </div>
        <div class="group">
            <h2>朋友</h2>
            <div class="ps hide">
                <p>11</p>
                <p>22</p>
                <p>33</p>
            </div>
        </div>
        <div class="group">
            <h2>陌生人</h2>
            <div class="ps hide">
                <p>111</p>
                <p>222</p>
                <p>333</p>
            </div>
        </div>
    </div>

    <script>
        $(function(){
            $('.contacts .group h2').click(function(){
                //所有联系人隐藏，显示被单击标题后的联系人
                //removeClass('hide')先删除自身属性，防止多次添加
                $('.contacts .ps').removeClass('hide').addClass('hide');
                $(this).next('div').removeClass('hide');
            })
        })
    </script>

</body>
</html>